import { combineReducers } from "redux";
import commonData from "./data";


const reducer = (state = commonData, action) => {
    switch (action.type) {
        case "SET_ALERTINFO":
            return Object.assign({}, state, {
                alertInfo: action.data
            });
        case "SET_USERINFO":
            return Object.assign({}, state, {
                userInfo: action.data
            });
        case "SET_IDENTITYLIST":
            return Object.assign({}, state, {
                identityList: action.data
            });
        case "SET_CURRENTIDENTITY":
            return Object.assign({}, state, {
                currentIdentity: action.data
            });
        case "SET_SYSADDR":
            return Object.assign({}, state, {
                sysAddrInfo: {
                    ...state.sysAddrInfo,
                    ...action.data
                }
            });
        case "SET_SKIN":
            return Object.assign({}, state, {
                skinInfo: {
                    ...action.data
                }
            });
        case "SET_SYSINFO":
            return Object.assign({}, state, {
                sysInfo: {
                    ...action.data
                }
            });
        case "SET_BACKUPSHISTORYINFO":
            return Object.assign({}, state, {
                backupsHistoryInfo: {
                    ...action.data
                }
            });
        default:
            return state;
    }
}

/**
 * 如果有多个reducer函数，则可以使用combineReducers进行合并
 *export default combineReducers({
     reducer1,
     reducer2
 })
 */
export default reducer;